/**
 * ipassbook 0.6.0
 * Copyright (C)2009 wateray and contributors
 * wateray@gmail.com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

package com.wateray.ipassbook.kernel;

import java.io.IOException;

import org.apache.log4j.Logger;

import com.wateray.ipassbook.util.SystemProperties;
import com.wateray.ipassbook.util.log4j.Log;

/**
 * @author wateray
 * @create 2009-5-31
 */
public class Kernel {
	private Logger logger = Log.getLogger(this.getClass());
	private static Kernel kernel = null;
	
	private Kernel(){}
	
	
	public static Kernel genInstance(){
		if(kernel == null){
			kernel = new Kernel();
		}
		return kernel;
	}
	
	/**
	 * Called when restarting application
	 */
	public void restart() {
		try {
			// Store all configuration and finish all active modules

			// Build a process builder with OS-specific command and saved arguments
			ProcessBuilder pb = new ProcessBuilder(SystemProperties.OS.getLaunchCommand());

			System.out.println(pb.command().toString());

			// Start new application instance
			pb.start();

		} catch (IOException e) {
			logger.error(e.getMessage(), e);
		} finally {
			// Exit normally
			System.exit(0);
		}
	}
}
